﻿using System;
using System.Linq;

namespace IllicitOnion.LinqDimensions
{
	public partial class CompoundEnumerable<T0, T1>
	{
		public virtual void ForEach(Action<T0, T1> action)
		{
			var i = 0;
			m_Left.ForEach(t0 =>
			              	{
			              		T1 t1;
			              		try
			              		{
			              			t1 = m_Right.ElementAt(i);
			              		}
			              		catch (ArgumentOutOfRangeException)
			              		{
			              			throw new ArgumentException(
			              				String.Format(
			              					"CompoundEnumerable's lists were not of equal size - list 0 had at least {0} elements but list 1 had only {1}",
			              					i, m_Right.Count()));
			              		}
			              		action(t0, t1);
			              		++i;
			              	});
		}
	}

	public partial class CompoundEnumerable<T0, T1, T2>
	{
		public void ForEach(Action<T0, T1, T2> action)
		{
			var i = 0;
			m_Left.ForEach((t0, t1) =>
			{
				T2 t2;
				try
				{
					t2 = m_Right.ElementAt(i);
				}
				catch (ArgumentOutOfRangeException)
				{
					throw new ArgumentException(
						String.Format(
							"CompoundEnumerable's lists were not of equal size - list 0 had at least {0} elements but list 2 had only {1}",
							i, m_Right.Count()));
				}
				action(t0, t1, t2);
				++i;
			});
		}
	}
}
